package com.pipe.servicepipe.config;

import com.pipe.servicepipe.service.PipeAdminService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;

import javax.annotation.Resource;

/**
 * @author Administrator
 * @ClassName PipeSecurityConfig
 * @Author HETAO
 * @Date 2020/7/16 11:24
 */
@Configuration
/**
 * prePostEnabled： 确定 前置注解[@PreAuthorize,@PostAuthorize,..] 是否启用
 * securedEnabled： 确定安全注解 [@Secured] 是否启用
 * jsr250Enabled： 确定 JSR-250注解 [@RolesAllowed..]是否启用
 */
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
public class PipeSecurityConfig extends WebSecurityConfig {

    @Resource
    private PipeAdminService pipeAdminService;
    /**
     * 模拟用户
     * @return
     */
    @Override
    @Bean
    public UserDetailsService userDetailsService() {
        return username -> pipeAdminService.loadUserByUsername(username);
    }
}
